package com.xjtu.project.controller.user;

import com.xjtu.project.common.utls.JsonResponse;
import com.xjtu.project.model.domain.Cart;
import com.xjtu.project.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private CartService CartService;

    @GetMapping("/add")
    public JsonResponse<String> add(@RequestParam("shoeId") Integer shoeId,@RequestParam("size") Integer size) {
        CartService.add(shoeId,size);
        return JsonResponse.success(null);
    }

    @GetMapping("/list")
    public JsonResponse<List<Cart>> list() {
        return JsonResponse.success(CartService.list());
    }
    @GetMapping("/sub")
    public JsonResponse<String> sub(@RequestParam("shoeId") Integer shoeId) {
        CartService.sub(shoeId);
        return JsonResponse.success(null);
    }
    @DeleteMapping("/clean")
    public JsonResponse<String> clean() {
        CartService.remove(null);
        return JsonResponse.success(null);
    }
}
